iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 1
0
自我挑戰組

霍普菜鳥的資訊工作雜記系列 第 24

D24-試一下socket小練習

  • 分享至 

  • xImage
  •  
let net = require('net')
let socket = new net.Socket()
let options = {
  'host': process.argv[2] ,
  'port': process.argv[3]
}

socket.on('connect', function () {
    console.log('connect');
    let buf = buffer.from(new String('this is a test'));
    socket.write(buf);
})

socket.on('data',console.log);
socket.on('error', console.error);
console.log("try",options.host,"port",options.port )
socket.connect(options)
openSocket() {
    this.merge = this.socketMerge;
    this.socket = io.connect(this.serverURI), {
        'reconnection': true,
        'reconnectionDelay': 1500,
        'reconnectionDelayMax': 3000,
        'reconnectionAttempts': 3
    };
    this.socket.on("update", data => {
        this.update(data);
        this.mergeLocal;
        if (this.onSocketDataUpdate)
            this.onSocketDataUpdate(data);
    });
}
;
closeSocket() {
    this.socket.closeSocket();
    this.merge = this.defalutmerge;
}

socketMerge() {
    var diff = this.mergeLocal();
    this.socket.emit("update", diff);
}

上一篇
D23-試試新玩意Deno
下一篇
D25-小試cordova ble的測試
系列文
霍普菜鳥的資訊工作雜記31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言